<template>
  <div class="index">
    <Location class="index-location" type="agent" />
    <div class="index-advertising">
      <!-- 代理身份 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">代理身份</div>
        <div class="index-advertising-form-right">
          <el-radio-group v-model="field.formData.shenfen">
            <el-radio :label="1">企业</el-radio>
            <el-radio :label="2">个人</el-radio>
          </el-radio-group>
        </div>
      </div>
      <!-- 公司名称 -->
      <div class="index-advertising-form">
        <div class="index-advertising-form-label">公司名称</div>
        <div class="index-advertising-form-input">
          <el-input
            v-model="field.formData.shop_name"
            placeholder="请输入您的公司名称"
          ></el-input>
        </div>
      </div>
      <!-- 公司简介 -->
      <div class="index-advertising-startform">
        <div class="index-advertising-form-label">公司简介</div>
        <div class="index-advertising-form-collect">
          <div class="index-advertising-form-text">
            <el-input
              v-model="field.formData.shop_intro"
              placeholder="请输入您的公司简介"
              type="textarea"
              rows="8"
              resize="none"
              size="medium"
            ></el-input>
          </div>
        </div>
      </div>
      <!-- 商品信息 -->
      <div class="index-advertising-startform">
        <div class="index-advertising-form-label">商品信息</div>
        <div class="index-advertising-form-collectwrap">
          <div class="index-advertising-form-linecollect">
            <div class="index-advertising-form-lineinput">
              <el-input
                v-model="field.formData.goods[0].goods_name"
                placeholder="请输入商品名称"
              ></el-input>
            </div>
            <div class="index-advertising-form-linetext">
              <el-input
                v-model="field.formData.goods[0].goods_content"
                placeholder="请输入商品简介"
                type="textarea"
                rows="3"
                resize="none"
                size="medium"
              ></el-input>
            </div>
            <div class="index-advertising-form-linecolumn">
              <!-- <img
                class="index-advertising-form-lineicon"
                src="@/assets/images/image(65).png"
              />
              <div class="index-advertising-form-linetitle">上传商品图片</div> -->
              <upload v-model:pic="field.formData.goods[0].original_img" />
            </div>
          </div>
          <div class="index-advertising-form-group">
            <div
              class="index-advertising-form-confirm"
              @click="field.sendShopDai"
            >
              立即提交
            </div>
            <div class="index-advertising-form-reset" @click="field.cleanField">
              重置
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ToastBottom, setObj, getObj } from "@/utils/index";
import { onUnmounted, computed, ref, reactive, toRefs, inject } from "vue";
import { useRoute, useRouter } from "vue-router";
import Location from "@/components/location/index";
import upload from "@/components/upload/index";
import { ElMessage } from "element-plus";

//获取路由
const $_route = useRoute();
const $_router = useRouter();
//获取接口
const $_api = inject("$api");
const field = reactive({
  formData: {
    token: getObj("health_token"),
    shenfen: "",
    shop_name: "",
    shop_intro: "",
    goods: [{ goods_name: "", goods_content: "", original_img: "" }],
  },
  sendShopDai: async () => {
    const obj = field.objFilter(field.formData);
    console.log(field.formData, obj, "obj");
    const results = await $_api.shopDai(field.formData);
    if (results && results.status > 0) {
      ElMessage.success(results.info);
    }
    field.cleanField();
  },
  cleanField: () => {
    field.formData.shenfen = "";
    field.formData.shop_name = "";
    field.formData.shop_intro = "";
    field.formData.goods[0].goods_name = "";
    field.formData.goods[0].goods_content = "";
    field.formData.goods[0].original_img = "";
  },
  objFilter: obj => {
    obj.goods = JSON.stringify(obj.goods);
  },
});
</script>

<style lang="scss" scoped>
.index {
  @include flex(flex-start, center);
  flex-direction: column;
  margin: 5px auto 0;
  width: 1200px;
}
.index-location {
  flex-shrink: 0;
  width: 100%;
  height: 105px;
}
.index-advertising {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  margin-top: 13px;
  margin-bottom: 20px;
  width: 100%;
}
.index-advertising-form {
  @include flex(flex-start, center);
  margin-bottom: 20px;
  width: 533px;
}
.index-advertising-startform {
  @include flex(flex-start, flex-start);
  margin-bottom: 20px;
  width: 533px;
  .index-advertising-form-label {
    margin-top: 5px;
  }
}
.index-advertising-form-label {
  width: 100px;
  text-align: left;
  font-size: 18px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 25px;
}
.index-advertising-form-right {
  font-size: 18px;
}
.index-advertising-form-input {
  width: 100%;
  height: 40px;
  background: #f4f4f4;
  opacity: 0.79;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
}
.index-advertising-form-lineinput {
  width: 100%;
  height: 40px;
  background: #f4f4f4;
  opacity: 0.79;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
  border-bottom: 1px solid #e1e1e1;
}
.index-advertising-form-select {
  width: 533px;
  height: 40px;
  background: #f4f4f4;
  opacity: 0.79;
}
.index-advertising-form-collect {
  @include flex(flex-start, center);
  flex-direction: column;
  width: 100%;
}
.index-advertising-form-collectwrap {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  width: 100%;
}
.index-advertising-form-linecollect {
  @include flex(flex-start, flex-start);
  flex-direction: column;
  padding: 0 20px;
  width: 100%;
  box-sizing: border-box;
  background: #f4f4f4;
  opacity: 0.79;
}
.index-advertising-form-text {
  width: 100%;
  height: 173px;
  background: #f4f4f4;
  opacity: 0.79;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
}
.index-advertising-form-linetext {
  width: 100%;
  //   height: 173px;
  background: #f4f4f4;
  opacity: 0.79;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
}
.index-advertising-form-linecolumn {
  @include flex(center, center);
  flex-direction: column;
  margin: 20px 0;
  width: 292px;
  height: 191px;
  background: #f6f6f6;
  box-shadow: 0px 2px 8px 0px rgba(202, 202, 202, 0.5);
  border-radius: 6px;
}
.index-advertising-form-lineimage {
  width: 233px;
  height: 159px;
}
.index-advertising-form-lineicon {
  margin-bottom: 10px;
  width: 32px;
  height: 32px;
}
.index-advertising-form-linetitle {
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #9e9e9e;
  line-height: 22px;
}
.index-advertising-form-group {
  @include flex(flex-start, center);
  margin-top: 20px;
  width: 100%;
}
.index-advertising-form-confirm {
  margin-right: 67px;
  flex-shrink: 0;
  flex-grow: 1;
  height: 36px;
  line-height: 36px;
  text-align: center;
  background: #df7935;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  cursor: pointer;
}
.index-advertising-form-reset {
  flex-shrink: 0;
  flex-grow: 1;
  height: 36px;
  line-height: 36px;
  text-align: center;
  background: #e1e1e1;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #6d6d6d;
  cursor: pointer;
}
</style>
<style lang="scss" scoped>
.index-advertising-form-right :deep(.el-radio) {
  margin-right: 20px;
}

.index-advertising-form-input :deep(.el-input__inner) {
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-lineinput :deep(.el-input__inner) {
  padding-left: 0;
  padding-right: 0;
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-select :deep(.el-input__inner) {
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-select :deep(.el-select) {
  width: 100%;
}
.index-advertising-form-text :deep(.el-textarea__inner) {
  width: 100%;
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
.index-advertising-form-linetext :deep(.el-textarea__inner) {
  padding-left: 0;
  padding-right: 0;
  width: 100%;
  border-radius: 0;
  border: none;
  background: #f4f4f4;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #2f2f2f;
  line-height: 20px;
  &::placeholder {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #9e9e9e;
    line-height: 22px;
  }
}
</style>
